package org.hellojboss.quickstart.security.dao.jpa;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.hellojboss.quickstart.security.dao.ICRUDDao;

public abstract class AbstractJPADao implements ICRUDDao {
	@PersistenceContext(unitName="quickstart")
	protected EntityManager entityManager;
	private Class<?> clazz;
	public AbstractJPADao(Class<?> clazz) {
		this.clazz = clazz;
	}
	
	public Object get(Object id) {
		return entityManager.find(clazz,id);
	}
	
	public void save(Object entity) {
		entityManager.persist(entity);
	}
	
	public void delete(Object entity) {
		entityManager.remove(entity);
	}
	
	public void update(Object entity) {
		entityManager.merge(entity);
	}
	
}
